# 将测试用例打包
def parse_data(cases, requests, responses):
    data = []

    for i in range(0, len(requests)):
        row = {}
        row["identification"] = i  # 测试用例标识
        row["priority"] = "高"  # 优先级
        row["description"] = get_description(cases[i])  # 测试说明
        row["post_condition"] = ""  # 预置条件
        row["steps"] = get_input(cases[i]),  # 测试步骤
        row["expected_output"] = responses[i].body,  # 预期输出
        row["result"] = "一致",  # 实际结果

        data.append(row)
    return data


def get_description(request_case):
    description = ""
    params = ""
    body = ""
    headers = ""

    for item in request_case["body"].keys():
        param = request_case["body"][item]
        body += param["description"] + " "

    for item in request_case["headers"].keys():
        param = request_case["headers"][item]
        headers += param["description"] + " "

    for item in request_case["params"].keys():
        param = request_case["params"][item]
        params += param["description"] + " "

    description += params if len(params) > 0 else ""
    description += body if len(body) > 0 else ""
    description += headers if len(headers) > 0 else ""

    return description

def get_input(request_case):
    input = {}
    params = {}
    body = {}
    # headers = {}

    for item in request_case["body"].keys():
        param = request_case["body"][item]
        body[item] = param["value"]

    # for item in request_case["headers"].keys():
    #     param = request_case["headers"][item]
    #     headers[item] = param["value"]

    for item in request_case["params"].keys():
        param = request_case["params"][item]
        params[item] = param["value"]

    # input["headers"] = headers
    input["params"] = params
    input["body"] = body

    return str(input)


# 将测试用例的请求体部分格式化为request参数
def format_body(body):
    result = {}
    for key in body.keys():
        value = body[key]["value"]
        result[key] = value
    return result

def format_params(params):
    result = {}
    for key in params.keys():
        value = params[key]["value"]
        result[key] = value
    return result